package com.util;

import com.dao.BaseAbstractDao;
import com.dao.BaseDao;
import com.entity.User;
import com.service.BaseService;
import com.service.impl.UserServiceImpl;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class SpringMvcTest {

	@Autowired
	BaseDao<User> userDao;
	
	@Autowired
	BaseService<User> userService;

	@Autowired
    BaseAbstractDao<User> baseUserDao;

	@Test
    public void testAbstarctUser(){
        System.out.println(baseUserDao.selectAll().size());;
    }

    @Test
    public void testAbstarctInsert(){
	    User user=new User();
//	    user.setId(IDUtil.getId());
	    user.setEmail("1912198008@qq.com");
	    user.setPassword("pass");
//	    user.setDate(new Date());
        System.out.println(baseUserDao.insert(user));
    }

    @Test
    public void testAbstarctUpdate(){
        User user=new User();
        user.setId("8a76aa4eb9824418a22caa8b7748af60");
        user.setEmail("1912198008@qq.com");
        user.setPassword("password");
//        user.setDate(new Date());
        System.out.println(baseUserDao.update(user));
    }
	
	@Test
	public void testLogin(){
		System.out.println(((UserServiceImpl)userService).deleteById("id"));
	}

	@Test
    public void saveUser(){
	    User user=new User();
	    user.setEmail("1912198008@qq.com");
	    user.setPassword("pass");
	    userService.insert(user);
    }

    @Test
    public void deleteUser(){
        System.out.println(userService.deleteById("122280b663f74b9a919464c732c881f6"));
    }
}
